package com.example.demo.util;

import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ImgUtil {
    public static String imgToBase64(String imgname) throws IOException {
        InputStream in = new FileInputStream("D:/dhcProject/images/"+imgname);
        byte[] data = new byte[in.available()];
        in.read(data);
        in.close();
        BASE64Encoder encoder=new BASE64Encoder();
        String  img=encoder.encode(data);
        return img;
    }
}
